home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / HD-Installer / jst_dev / sources / src / loaders / JamesPond3CD32 / jp3hd.asm < prev    next >
Assembly Source File  |  2000-04-12  |  10KB  |  652 lines

  1. ; *** James Pond CD32 HD Loader
  2.  
  3. ; ** $29A9,$29AB: level. 4 saves
  4. ; ** $7D46,$7679: vies
  5. ; ** $7676,$7F7A: score
  6.  
  7. ; ** $7BC5 : $FF save item
  8.  
  9.     include    "jst.i"
  10.  
  11.     HD_PARAMS    "",0,0
  12.  
  13.     MACHINE    68020
  14.  
  15. SAVELEN = 168
  16. DATALEN = SAVELEN+$40
  17.  
  18. _loader:
  19.     RELOC_MOVEL    D1,noosswap
  20.     RELOC_MOVEL    D2,joypad
  21.     RELOC_MOVEL    D3,hdload
  22.     beq    skalloc$
  23.  
  24.     move.l    #639000,D0
  25.     JSRABS    AllocExtMem
  26.     RELOC_MOVEL    D0,SwapBase
  27.     beq    MemErr
  28.     cmp.l    #$200000,D0
  29.     bcs    MemErr
  30. skalloc$
  31.  
  32.     Mac_printf    "James Pond HD Loader V1.1"
  33.     Mac_printf    "Programmed by JF Fabre © 1997"
  34.  
  35.     TESTFILE    loadername
  36.     tst.l    D0
  37.     bne    MainErr
  38.  
  39.     TESTFILE    progname
  40.     tst.l    D0
  41.     bne    MainErr
  42.  
  43.     ; *** some system checks
  44.  
  45.     JSRGEN    GetAttnFlags
  46.     btst    #AFB_68020,D0
  47.     beq    CpuErr
  48.  
  49.     JSRABS    Test2MBChip
  50.     tst.l    D0
  51.     bne    ChipErr
  52.  
  53.     ; *** load savegame file
  54.  
  55.     bsr    ReadSaves
  56.     tst.l    D0
  57.     beq    sok$
  58.  
  59.     NEWLINE
  60.     Mac_printf    "Savegame file not found"
  61. sok$
  62.  
  63.     ; *** load game data
  64.  
  65.     move.l    #5000,D0
  66.     JSRABS    LoadSmallFiles
  67.  
  68.     ; *** install save game on exit
  69.     
  70.     RELOC_TSTL    noosswap
  71.     bne    sks$
  72.  
  73.     lea    WriteSaves(pc),A0
  74.     JSRGEN    SetExitRoutine
  75. sks$
  76.  
  77.     moveq.l    #0,D0
  78.     move.l    #CACRF_CopyBack,D1
  79.     JSRABS    Degrade
  80.  
  81. ; *** Boot the game
  82.  
  83.     GO_SUPERVISOR
  84.     moveq.l    #0,D1            ; enable low memory consumption
  85.     SAVE_OSDATA    $200000
  86.  
  87.     lea    $200000,A7
  88.  
  89.     lea    $80000,A1
  90.     lea    loadername(pc),A0
  91.     moveq.l    #0,D0
  92.     moveq.l    #-1,D1
  93.     bsr    ReadAFile
  94.     
  95.     lea    $80000,A0
  96.     bsr    PatchLoader
  97.  
  98.     JSRGEN    FlushCachesHard
  99.  
  100.     nop
  101.     nop
  102.     jmp    $88(A0)
  103.     nop
  104.     nop
  105.  
  106. PatchGame:
  107.     move.w    #$601A,$174.W
  108.  
  109.     GETUSRADDR    ReadAFile
  110.     move.l    D0,$1B4.W
  111.     move.l    D0,$1EC.W
  112.  
  113.     GETUSRADDR    PatchProg
  114.     move.l    D0,$20C.W
  115.  
  116.     JSRGEN    FlushCachesHard
  117.     jmp    $100.W
  118.  
  119.  
  120. PatchLoader:
  121.     move.w    #$6016,$CA(A0)
  122.     GETUSRADDR    PatchGame
  123.     move.l    D0,$110(A0)
  124.  
  125.     STORE_REGS
  126.     move.l    A0,A1
  127.     lea    $42DF(A1),A1
  128.     move.l    A1,D1
  129.     lea    mess1(pc),A2
  130.     move.l    A2,D0
  131.     JSRGEN    StrcpyAsm
  132.  
  133.     move.l    A0,A1
  134.     lea    $42FA(A1),A1
  135.     move.l    A1,D1
  136.     lea    mess2(pc),A0
  137.     move.l    A0,D0
  138.     JSRGEN    StrcpyAsm
  139.  
  140.  
  141.     RESTORE_REGS
  142.     rts
  143.  
  144. PatchProg:
  145.     PATCHUSRJMP    $112000,ReadAFile
  146.  
  147.     ; *** installs kb patch
  148.  
  149.     PATCHUSRJSR    $13972E,kbread
  150.  
  151.     ; *** installs button 2/3/4 emulation (if JOYPAD tooltype off)
  152.  
  153.     RELOC_TSTL    joypad
  154.     bne    skipj$
  155.     PATCHUSRJSR    $1398C6,emubut2
  156.  
  157.     ; *** up = jump (problems with saves, I had to fix it by hand)
  158.  
  159.     move.l    #$00040011,$1397D4
  160.  
  161.     ; *** removes a $BFE001 bit change
  162.  
  163.     move.w    #$600E,$139878
  164.  
  165.     ; *** fix the up = jump problem easily
  166.  
  167.     PATCHUSRJSR    $143BF4,SaveOk
  168.     PATCHUSRJSR    $143C38,SaveOk
  169.  
  170.     ; *** changes START into SPACE
  171.  
  172.     lea    $11F9FF,A1
  173.     bsr    CorrectStartString
  174.     lea    $11FB3B,A1
  175.     bsr    CorrectStartString
  176.     lea    $12013C,A1
  177.     bsr    CorrectStartString
  178.  
  179.     ; *** changes YELLOW into FIRE
  180.  
  181.     move.l    #' FIR',$120110
  182.     move.l    #'E  T',$120114
  183. skipj$
  184.  
  185.     ; *** reinstalls my exception handler
  186.  
  187.     PATCHUSRJMP    $15A866,RestoreTraps
  188.  
  189.     ; *** $144708: load game (low level)
  190.     ; *** $14477C: save game (low level)
  191.  
  192.     ; *** we save at a higher level
  193.     ; *** in and from RAM:
  194.  
  195.     PATCHUSRJMP    $143F9A,LoadGame
  196.     PATCHUSRJMP    $143FBA,SaveGame
  197.  
  198.     ; *** to be able to load scores
  199.  
  200.     PATCHUSRJSR    $143C16,GetScore
  201.     PATCHUSRJSR    $135806,ClearScore
  202.  
  203.     ; *** decrunch in fastmem (fake PP20 file)
  204.  
  205.     PATCHUSRJMP    $139660,Decrunch
  206.  
  207.     JSRGEN    FlushCachesHard
  208.     jmp    $11CC00
  209.  
  210.  
  211. Decrunch:
  212.     MOVEM.L    D1-D7/A0-A5,-(A7)    ;00: 48E77FFC
  213.     PEA    dec_0011(PC)        ;04: 487A00AC
  214.     LEA    4(A0),A4        ;08: 49E80004
  215.     ADDA.L    (A0),A0            ;0C: D1D0
  216.     MOVEA.L    A1,A3            ;0E: 2649
  217.     MOVEQ    #3,D6            ;10: 7C03
  218.     MOVEQ    #1,D4            ;12: 7801
  219.     MOVEQ    #7,D7            ;14: 7E07
  220.     MOVEQ    #1,D5            ;16: 7A01
  221.     MOVEA.L    A3,A2            ;18: 244B
  222.     MOVE.L    -(A0),D1        ;1A: 2220
  223.     TST.B    D1            ;1C: 4A01
  224.     BEQ.S    dec_0000        ;1E: 6706
  225.     BSR.S    dec_0004        ;20: 612A
  226.     SUB.L    D4,D1            ;22: 9284
  227.     LSR.L    D1,D5            ;24: E2AD
  228. dec_0000:
  229.     LSR.L    #8,D1            ;26: E089
  230.     ADDA.L    D1,A3            ;28: D7C1
  231.     MOVEA.L    D1,A5            ;2A: 2A41
  232. dec_0001:
  233.     BSR.S    dec_0004        ;2C: 611E
  234.     BCS.S    dec_000B        ;2E: 653E
  235.     MOVEQ    #0,D2            ;30: 7400
  236. dec_0002:
  237.     MOVE    D4,D0            ;32: 3004
  238.     BSR.S    dec_0007        ;34: 6124
  239.     ADD    D1,D2            ;36: D441
  240.     CMP    D6,D1            ;38: B246
  241.     BEQ.S    dec_0002        ;3A: 67F6
  242. dec_0003:
  243.     MOVEQ    #7,D0            ;3C: 7007
  244.     BSR.S    dec_0007        ;3E: 611A
  245.     MOVE.B    D1,-(A3)        ;40: 1701
  246.     DBF    D2,dec_0003        ;42: 51CAFFF8
  247.     CMPA.L    A3,A2            ;46: B5CB
  248.     BCS.S    dec_000B        ;48: 6524
  249.     RTS                ;4A: 4E75
  250. dec_0004:
  251.     LSR.L    D4,D5            ;4C: E8AD
  252.     BEQ.S    dec_0005        ;4E: 6702
  253.     RTS                ;50: 4E75
  254. dec_0005:
  255.     MOVE.L    -(A0),D5        ;52: 2A20
  256.     ROXR.L    D4,D5            ;54: E8B5
  257.     RTS                ;56: 4E75
  258. dec_0006:
  259.     SUB    D4,D0            ;58: 9044
  260. dec_0007:
  261.     MOVEQ    #0,D1            ;5A: 7200
  262. dec_0008:
  263.     LSR.L    D4,D5            ;5C: E8AD
  264.     BEQ.S    dec_000A        ;5E: 6708
  265. dec_0009:
  266.     ROXL.L    D4,D1            ;60: E9B1
  267.     DBF    D0,dec_0008        ;62: 51C8FFF8
  268.     RTS                ;66: 4E75
  269. dec_000A:
  270.     MOVE.L    -(A0),D5        ;68: 2A20
  271.     ROXR.L    D4,D5            ;6A: E8B5
  272.     BRA.S    dec_0009        ;6C: 60F2
  273. dec_000B:
  274.     MOVE    D4,D0            ;6E: 3004
  275.     BSR.S    dec_0007        ;70: 61E8
  276.     MOVEQ    #0,D0            ;72: 7000
  277.     MOVE.B    0(A4,D1.W),D0        ;74: 10341000
  278.     MOVE    D1,D2            ;78: 3401
  279.     CMP    D6,D2            ;7A: B446
  280.     BNE.S    dec_000E        ;7C: 6616
  281.     BSR.S    dec_0004        ;7E: 61CC
  282.     BCS.S    dec_000C        ;80: 6502
  283.     MOVEQ    #7,D0            ;82: 7007
  284. dec_000C:
  285.     BSR.S    dec_0006        ;84: 61D2
  286.     MOVE    D1,D3            ;86: 3601
  287. dec_000D:
  288.     MOVEQ    #2,D0            ;88: 7002
  289.     BSR.S    dec_0007        ;8A: 61CE
  290.     ADD    D1,D2            ;8C: D441
  291.     CMP    D7,D1            ;8E: B247
  292.     BEQ.S    dec_000D        ;90: 67F6
  293.     BRA.S    dec_000F        ;92: 6004
  294. dec_000E:
  295.     BSR.S    dec_0006        ;94: 61C2
  296.     MOVE    D1,D3            ;96: 3601
  297. dec_000F:
  298.     ADD    D4,D2            ;98: D444
  299. dec_0010:
  300.     MOVE.B    0(A3,D3.W),-(A3)    ;9A: 17333000
  301.     MOVE    D3,-(A7)        ;9E: 3F03
  302.     ANDI    #$000F,D3        ;A0: 0243000F
  303.     MOVE    (A7)+,D3        ;A4: 361F
  304.     DBF    D2,dec_0010        ;A6: 51CAFFF2
  305.     CMPA.L    A3,A2            ;AA: B5CB
  306.     BCS    dec_0001        ;AC: 6500FF7E
  307.     RTS                ;B0: 4E75
  308. dec_0011:
  309.     MOVE.L    A5,D0            ;B2: 200D
  310.     MOVEM.L    (A7)+,D1-D7/A0-A5    ;B4: 4CDF3FFE
  311.     RTS                ;B8: 4E75
  312.     
  313.  
  314. CorrectStartString
  315.     lea    spacestr(pc),A0
  316.     moveq    #4,D0
  317. cps$
  318.     move.b    (A0)+,(A1)+
  319.     dbf    D0,cps$
  320.     rts
  321.  
  322. SaveOk:
  323.     movem.l    D1-D2,-(sp)
  324.     move.w    $DFF000+joy1dat,D1
  325.     move.w    D1,D2
  326.     lsr.w    #1,D1
  327.     eor.w    D2,D1
  328.  
  329.     btst    #8,D1
  330.     movem.l    (sp)+,D1-D2
  331.     bne    up
  332.  
  333.     lea    $9E954,A0
  334.     rts            ; fire pressed: do save/load
  335. up:
  336.     lea    4(A7),A7
  337.     jmp    $143BB0
  338.  
  339. ClearScore:
  340.     RELOC_TSTB    GameLoaded
  341.     bne    sk$
  342.     clr.l    $7F78.L        ; clear score on beginning of game
  343. sk$
  344.     RELOC_CLRB    GameLoaded
  345.     rts
  346.  
  347. GetScore:
  348.     movem.l    D0/A1,-(sp)
  349.     moveq    #0,D0
  350.     move.w    $807E,D0
  351.     lea    scorebuffer(pc),A1
  352.     move.l    (A1,D0.L*4),$7F78.W    ; restore score
  353.  
  354.     RELOC_STB    GameLoaded        ; to tell not to clear the score
  355.  
  356.     movem.l    (sp)+,D0/A1
  357.     JMP    $143972        ; original game
  358.  
  359. LoadGame:
  360.     movem.l    A0-A1,-(sp)
  361.     lea    savebuffer(pc),A0
  362.     lea    $9E954,A1
  363.     move.b    #SAVELEN-1,D0
  364. copy$
  365.     move.b    (A0)+,(A1)+
  366.     dbf    D0,copy$
  367.     movem.l    (sp)+,A0-A1
  368.  
  369.     moveq.l    #0,D0        ; always OK
  370.     tst.l    D0
  371.     rts
  372.  
  373. SaveGame:
  374.     movem.l    A0-A1,-(sp)    
  375.     lea    savebuffer(pc),A1
  376.     lea    $9E954,A0
  377.     move.b    #SAVELEN-1,D0
  378. copy$
  379.     move.b    (A0)+,(A1)+
  380.     dbf    D0,copy$
  381.  
  382.     moveq.l    #0,D0
  383.     move.w    $807E,D0    ; # of save
  384.  
  385.     lea    scorebuffer(pc),A1
  386.     move.l    $7F78.W,(A1,D0.L*4)
  387.  
  388.     RELOC_STB    SaveChanged
  389.  
  390.     movem.l    (sp)+,A0-A1
  391.  
  392.     moveq.l    #0,D0        ; always OK
  393.     tst.l    D0
  394.     rts
  395.     
  396. ReadSaves:
  397.     lea    savename(pc),A0
  398.     lea    savebuffer(pc),A1
  399.     move.l    #DATALEN,D1
  400.     moveq.l    #0,D0
  401.     JSRGEN    ReadUserFileHD
  402.     rts
  403.  
  404. WriteSaves:
  405.     RELOC_TSTB    SaveChanged
  406.     beq    exit$
  407.     lea    savename(pc),A0
  408.     lea    savebuffer(pc),A1
  409.     move.l    #DATALEN,D1
  410.     moveq.l    #0,D0
  411.     JSRGEN    WriteUserFileHD        ; write file in the user directory
  412.     tst.l    D0            ; specified by SAVEDIR
  413.     bne    error$
  414. exit$
  415.     rts
  416. error$
  417.     Mac_printf    "** Could not write savegame file"
  418.     Mac_printf    "   Hit Return to exit"
  419.     JSRABS    WaitReturn
  420.     rts
  421.  
  422.  
  423. FileErr:
  424.     Mac_printf    "** Some files are missing. Please install the game properly"
  425.     Mac_printf    "** Hit RETURN to exit"
  426.     JSRABS    WaitReturn
  427.     rts
  428.  
  429. MainErr:
  430.     Mac_printf    "** Some files are missing. Please install the game properly"
  431.     JMPABS    CloseAll
  432.  
  433. MemErr:
  434.     Mac_printf    "** Not enough memory to run James Pond 3"
  435.     JMPABS    CloseAll
  436.  
  437. ChipErr:
  438.     Mac_printf    "** You need 2MB of chipmem to run James Pond 3"
  439.     JMPABS    CloseAll
  440.  
  441. CpuErr:
  442.     Mac_printf    "** You need a 68020 or better to run James Pond 3"
  443.     JMPABS    CloseAll
  444.  
  445.  
  446. ReadAFile:
  447.     RELOC_TSTL    hdload
  448.     bne    ReadAFileHD
  449.  
  450.     STORE_REGS
  451.  
  452.     tst.w    D0
  453.     bne    exit$
  454.  
  455.     moveq.l    #-1,D1        ; read all the file
  456.     JSRGEN    ReadFileFast
  457.  
  458.     tst.l    D0
  459.     bne    NotFound        ; file not found
  460.  
  461. exit$
  462.     RESTORE_REGS        ; length in D1
  463.     moveq.l    #0,D0
  464.     rts
  465.  
  466. NotFound:
  467.     lea    FileErr(pc),A0
  468.     JSRGEN    SetExitRoutine
  469.     JSRGEN    InGameExit
  470.     move.w    #$F00,$DFF180
  471.     bra    NotFound
  472.  
  473. ReadAFileHD:
  474.     STORE_REGS
  475.  
  476.     tst.w    D0
  477.     bne    exit$
  478.     move.l    A1,A2
  479.     move.l    SwapBase(pc),A1
  480.  
  481.     GETUSRADDR    reloc_name
  482.     move.l    D0,D1
  483.     move.l    A0,D0
  484.     JSRGEN    StrcpyAsm    ; relocates the name (because of gap)
  485.     move.l    D1,A0
  486.  
  487.     moveq.l    #0,